********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

****
** Open ANES 2008-2009 Panel
****

set more off

* use "2008 panel.dta"

********************************************************************************

****
** Data cleaning and recoding
****

** WAVE 6 

* McCain

* amend const for same sex
gen gaymccain6 = .
replace gaymccain6 = 4 if W6PJ1 == 12
replace gaymccain6 = 1 if W6PJ2_OP == 10
replace gaymccain6 = 2 if W6PJ2_OP == 11
replace gaymccain6 = 3 if W6PJ2_OP == 12
replace gaymccain6 = 5 if W6PJ2_FA == 12
replace gaymccain6 = 6 if W6PJ2_FA == 11
replace gaymccain6 = 7 if W6PJ2_FA== 10

* tax the rich
gen taxmccain6 = . 
replace taxmccain6 = 4 if W6PJ4 == 12
replace taxmccain6 = 1 if W6PJ5_OP == 10
replace taxmccain6 = 2 if W6PJ5_OP == 11
replace taxmccain6 = 3 if W6PJ5_OP == 12
replace taxmccain6 = 5 if W6PJ5_FA == 12
replace taxmccain6 = 6 if W6PJ5_FA == 11
replace taxmccain6 = 7 if W6PJ5_FA == 10

* gov pay for seniors' prescription drugs 
gen scriptmccain6 = .
replace scriptmccain6 = 4 if W6PJ7 == 12
replace scriptmccain6 = 1 if W6PJ8_OP == 10
replace scriptmccain6 = 2 if W6PJ8_OP == 11
replace scriptmccain6= 3 if  W6PJ8_OP == 12
replace scriptmccain6 = 5 if W6PJ8_FA == 12
replace scriptmccain6 = 6 if W6PJ8_FA == 11
replace scriptmccain6 = 7 if W6PJ8_FA == 10

* gov pay for medical care
gen healthmccain6 = .
replace healthmccain6 = 4 if W6PJ13 == 12
replace healthmccain6 = 1 if W6PJ14_O == 10
replace healthmccain6 = 2 if W6PJ14_O == 11
replace healthmccain6= 3 if W6PJ14_O == 12
replace healthmccain6 = 5 if W6PJ14_F == 12
replace healthmccain6 = 6 if W6PJ14_F == 11
replace healthmccain6 = 7 if W6PJ14_F == 10

* detain terrorists 
gen terrormccain6 = .
replace terrormccain6 = 4 if W6PJ16 == 12
replace terrormccain6 = 1 if W6PJ17_O== 10
replace terrormccain6 = 2 if W6PJ17_O == 11
replace terrormccain6= 3 if  W6PJ17_O == 12
replace terrormccain6 = 5 if W6PJ17_F == 12
replace terrormccain6 = 6 if W6PJ17_F == 11
replace terrormccain6 = 7 if W6PJ17_F == 10

* Need FISA warrant to wiretap terrorists? 
gen fisamccain6 = .
replace fisamccain6 = 4 if W6PJ19 == 12
replace fisamccain6 = 1 if W6PJ20_O == 10
replace fisamccain6 = 2 if W6PJ20_O == 11
replace fisamccain6 = 3 if W6PJ20_O == 12
replace fisamccain6 = 5 if W6PJ20_F == 12
replace fisamccain6 = 6 if W6PJ20_F == 11
replace fisamccain6 = 7 if W6PJ20_F == 10

* Let immigrants work for 3 years, then send them back 
gen immigrantsmccain6 = .
replace immigrantsmccain6 = 4 if W6PJ22 == 12
replace immigrantsmccain6 = 1 if W6PJ23_O == 10
replace immigrantsmccain6 = 2 if W6PJ23_O == 11
replace immigrantsmccain6 = 3 if W6PJ23_O == 12
replace immigrantsmccain6 = 5 if W6PJ23_F == 12
replace immigrantsmccain6 = 6 if W6PJ23_F == 11
replace immigrantsmccain6 = 7 if W6PJ23_F == 10

* allowing immigrants to become citizens
gen citizenmccain6 = .
replace citizenmccain6 = 4 if W6PJ25 == 12
replace citizenmccain6 = 1 if W6PJ26_O == 10
replace citizenmccain6 = 2 if W6PJ26_O == 11
replace citizenmccain6 = 3 if W6PJ26_O == 12
replace citizenmccain6 = 5 if W6PJ26_F == 12
replace citizenmccain6 = 6 if W6PJ26_F == 11
replace citizenmccain6 = 7 if W6PJ26_F == 10

** Obama

* amend const for same sex
gen gayobama6 = .
replace gayobama6 = 4 if W6PB1 == 12
replace gayobama6 = 1 if W6PB2_OP == 10
replace gayobama6 = 2 if W6PB2_OP == 11
replace gayobama6 = 3 if W6PB2_OP == 12
replace gayobama6 = 5 if W6PB2_FA == 12
replace gayobama6 = 6 if W6PB2_FA == 11
replace gayobama6 = 7 if W6PB2_FA== 10

* tax the rich
gen taxobama6 = . 
replace taxobama6 = 4 if W6PB4 == 12
replace taxobama6 = 1 if W6PB5_OP == 10
replace taxobama6 = 2 if W6PB5_OP == 11
replace taxobama6 = 3 if W6PB5_OP == 12
replace taxobama6 = 5 if W6PB5_FA == 12
replace taxobama6 = 6 if W6PB5_FA == 11
replace taxobama6 = 7 if W6PB5_FA == 10

* gov pay for seniors' prescription drugs 
gen scriptobama6 = .
replace scriptobama6 = 4 if W6PB7 == 12
replace scriptobama6 = 1 if W6PB8_OP == 10
replace scriptobama6 = 2 if W6PB8_OP == 11
replace scriptobama6= 3 if  W6PB8_OP == 12
replace scriptobama6 = 5 if W6PB8_FA == 12
replace scriptobama6 = 6 if W6PB8_FA == 11
replace scriptobama6 = 7 if W6PB8_FA == 10

* gov pay for medical care
gen healthobama6 = .
replace healthobama6 = 4 if W6PB13 == 12
replace healthobama6 = 1 if W6PB14_O == 10
replace healthobama6 = 2 if W6PB14_O == 11
replace healthobama6= 3 if W6PB14_O == 12
replace healthobama6 = 5 if W6PB14_F == 12
replace healthobama6 = 6 if W6PB14_F == 11
replace healthobama6 = 7 if W6PB14_F == 10

* detain terrorists 
gen terrorobama6 = .
replace terrorobama6 = 4 if W6PB16 == 12
replace terrorobama6 = 1 if W6PB17_O== 10
replace terrorobama6 = 2 if W6PB17_O == 11
replace terrorobama6= 3 if  W6PB17_O == 12
replace terrorobama6 = 5 if W6PB17_F == 12
replace terrorobama6 = 6 if W6PB17_F == 11
replace terrorobama6 = 7 if W6PB17_F == 10

* Need FISA warrant to wiretap terrorists? 
gen fisaobama6 = .
replace fisaobama6 = 4 if W6PB19 == 12
replace fisaobama6 = 1 if W6PB20_O == 10
replace fisaobama6 = 2 if W6PB20_O == 11
replace fisaobama6 = 3 if W6PB20_O == 12
replace fisaobama6 = 5 if W6PB20_F == 12
replace fisaobama6 = 6 if W6PB20_F == 11
replace fisaobama6 = 7 if W6PB20_F == 10

* Let immigrants work for 3 years, then send them back 
gen immigrantsobama6 = .
replace immigrantsobama6 = 4 if W6PB22 == 12
replace immigrantsobama6 = 1 if W6PB23_O == 10
replace immigrantsobama6 = 2 if W6PB23_O == 11
replace immigrantsobama6 = 3 if W6PB23_O == 12
replace immigrantsobama6 = 5 if W6PB23_F == 12
replace immigrantsobama6 = 6 if W6PB23_F == 11
replace immigrantsobama6 = 7 if W6PB23_F == 10

* allowing immigrants to become citizens
gen citizenobama6 = .
replace citizenobama6 = 4 if W6PB25 == 12
replace citizenobama6 = 1 if W6PB26_O == 10
replace citizenobama6 = 2 if W6PB26_O == 11
replace citizenobama6 = 3 if W6PB26_O == 12
replace citizenobama6 = 5 if W6PB26_F == 12
replace citizenobama6 = 6 if W6PB26_F == 11
replace citizenobama6 = 7 if W6PB26_F == 10



** WAVE 9

** McCain
* amend const for same sex
gen gaymccain9 = .
replace gaymccain9 = 4 if W9PJ1 == 12
replace gaymccain9 = 1 if W9PJ2_O == 10
replace gaymccain9 = 2 if W9PJ2_O == 11
replace gaymccain9 = 3 if W9PJ2_O == 12
replace gaymccain9 = 5 if W9PJ2_F == 12
replace gaymccain9 = 6 if W9PJ2_F == 11
replace gaymccain9 = 7 if W9PJ2_F== 10

* tax the rich
gen taxmccain9 = . 
replace taxmccain9 = 4 if W9PJ4 == 12
replace taxmccain9 = 1 if W9PJ5_O == 10
replace taxmccain9 = 2 if W9PJ5_O == 11
replace taxmccain9 = 3 if W9PJ5_O == 12
replace taxmccain9 = 5 if W9PJ5_F == 12
replace taxmccain9 = 6 if W9PJ5_F == 11
replace taxmccain9 = 7 if W9PJ5_F == 10

* gov pay for seniors' prescription drugs 

gen scriptmccain9 = .
replace scriptmccain9 = 4 if W9PJ7 == 12
replace scriptmccain9 = 1 if W9PJ8_O == 10
replace scriptmccain9 = 2 if W9PJ8_O == 11
replace scriptmccain9= 3 if  W9PJ8_O == 12
replace scriptmccain9 = 5 if W9PJ8_F == 12
replace scriptmccain9 = 6 if W9PJ8_F == 11
replace scriptmccain9 = 7 if W9PJ8_F == 10

 
* gov pay for medical care
gen healthmccain9 = .
replace healthmccain9 = 4 if W9PJ13 == 12
replace healthmccain9 = 1 if W9PJ14_O == 10
replace healthmccain9 = 2 if W9PJ14_O == 11
replace healthmccain9= 3 if W9PJ14_O == 12
replace healthmccain9 = 5 if W9PJ14_F == 12
replace healthmccain9 = 6 if W9PJ14_F == 11
replace healthmccain9 = 7 if W9PJ14_F == 10

* detain terrorists 
gen terrormccain9 = .
replace terrormccain9 = 4 if W9PJ16 == 12
replace terrormccain9 = 1 if W9PJ17_O== 10
replace terrormccain9 = 2 if W9PJ17_O == 11
replace terrormccain9= 3 if  W9PJ17_O == 12
replace terrormccain9 = 5 if W9PJ17_F == 12
replace terrormccain9 = 6 if W9PJ17_F == 11
replace terrormccain9 = 7 if W9PJ17_F == 10

* Need FISA warrant to wiretap terrorists? 
gen fisamccain9 = .
replace fisamccain9 = 4 if W9PJ19 == 12
replace fisamccain9 = 1 if W9PJ20_O == 10
replace fisamccain9 = 2 if W9PJ20_O == 11
replace fisamccain9 = 3 if W9PJ20_O == 12
replace fisamccain9 = 5 if W9PJ20_F == 12
replace fisamccain9 = 6 if W9PJ20_F == 11
replace fisamccain9 = 7 if W9PJ20_F == 10

* Let immigrants work for 3 years, then send them back 
gen immigrantsmccain9 = .
replace immigrantsmccain9 = 4 if W9PJ22 == 12
replace immigrantsmccain9 = 1 if W9PJ23_O == 10
replace immigrantsmccain9 = 2 if W9PJ23_O == 11
replace immigrantsmccain9 = 3 if W9PJ23_O == 12
replace immigrantsmccain9 = 5 if W9PJ23_F == 12
replace immigrantsmccain9 = 6 if W9PJ23_F == 11
replace immigrantsmccain9 = 7 if W9PJ23_F == 10

* allowing immigrants to become citizens
gen citizenmccain9 = .
replace citizenmccain9 = 4 if W9PJ25 == 12
replace citizenmccain9 = 1 if W9PJ26_O == 10
replace citizenmccain9 = 2 if W9PJ26_O == 11
replace citizenmccain9 = 3 if W9PJ26_O == 12
replace citizenmccain9 = 5 if W9PJ26_F == 12
replace citizenmccain9 = 6 if W9PJ26_F == 11
replace citizenmccain9 = 7 if W9PJ26_F == 10



** Obama

* amend const for same sex
gen gayobama9 = .
replace gayobama9 = 4 if W9PB1 == 12
replace gayobama9 = 1 if W9PB2_OP == 10
replace gayobama9 = 2 if W9PB2_OP == 11
replace gayobama9 = 3 if W9PB2_OP == 12
replace gayobama9 = 5 if W9PB2_FA == 12
replace gayobama9 = 6 if W9PB2_FA == 11
replace gayobama9 = 7 if W9PB2_FA== 10

* tax the rich
gen taxobama9 = . 
replace taxobama9 = 4 if W9PB4 == 12
replace taxobama9 = 1 if W9PB5_OP == 10
replace taxobama9 = 2 if W9PB5_OP == 11
replace taxobama9 = 3 if W9PB5_OP == 12
replace taxobama9 = 5 if W9PB5_FA == 12
replace taxobama9 = 6 if W9PB5_FA == 11
replace taxobama9 = 7 if W9PB5_FA == 10

* gov pay for seniors' prescription drugs 
gen scriptobama9 = .
replace scriptobama9 = 4 if W9PB7 == 12
replace scriptobama9 = 1 if W9PB8_OP == 10
replace scriptobama9 = 2 if W9PB8_OP == 11
replace scriptobama9= 3 if  W9PB8_OP == 12
replace scriptobama9 = 5 if W9PB8_FA == 12
replace scriptobama9 = 6 if W9PB8_FA == 11
replace scriptobama9 = 7 if W9PB8_FA == 10

* gov pay for medical care
gen healthobama9 = .
replace healthobama9 = 4 if W9PB13 == 12
replace healthobama9 = 1 if W9PB14_O == 10
replace healthobama9 = 2 if W9PB14_O == 11
replace healthobama9= 3 if W9PB14_O == 12
replace healthobama9 = 5 if W9PB14_F == 12
replace healthobama9 = 6 if W9PB14_F == 11
replace healthobama9 = 7 if W9PB14_F == 10

* detain terrorists 
gen terrorobama9 = .
replace terrorobama9 = 4 if W9PB16 == 12
replace terrorobama9 = 1 if W9PB17_O== 10
replace terrorobama9 = 2 if W9PB17_O == 11
replace terrorobama9= 3 if  W9PB17_O == 12
replace terrorobama9 = 5 if W9PB17_F == 12
replace terrorobama9 = 6 if W9PB17_F == 11
replace terrorobama9 = 7 if W9PB17_F == 10

* Need FISA warrant to wiretap terrorists? 
gen fisaobama9 = .
replace fisaobama9 = 4 if W9PB19 == 12
replace fisaobama9 = 1 if W9PB20_O == 10
replace fisaobama9 = 2 if W9PB20_O == 11
replace fisaobama9 = 3 if W9PB20_O == 12
replace fisaobama9 = 5 if W9PB20_F == 12
replace fisaobama9 = 6 if W9PB20_F == 11
replace fisaobama9 = 7 if W9PB20_F == 10

* Let immigrants work for 3 years, then send them back 
gen immigrantsobama9 = .
replace immigrantsobama9 = 4 if W9PB22 == 12
replace immigrantsobama9 = 1 if W9PB23_O == 10
replace immigrantsobama9 = 2 if W9PB23_O == 11
replace immigrantsobama9 = 3 if W9PB23_O == 12
replace immigrantsobama9 = 5 if W9PB23_F == 12
replace immigrantsobama9 = 6 if W9PB23_F == 11
replace immigrantsobama9 = 7 if W9PB23_F == 10

* allowing immigrants to become citizens
gen citizenobama9 = .
replace citizenobama9 = 4 if W9PB25 == 12
replace citizenobama9 = 1 if W9PB26_O == 10
replace citizenobama9 = 2 if W9PB26_O == 11
replace citizenobama9 = 3 if W9PB26_O == 12
replace citizenobama9 = 5 if W9PB26_F == 12
replace citizenobama9 = 6 if W9PB26_F == 11
replace citizenobama9 = 7 if W9PB26_F == 10


* ideological differences

gen mccainideo6 = .
replace mccainideo6 = 1 if W6H10 == 10
replace mccainideo6 = 2 if W6H10 == 11
replace mccainideo6 = 3 if W6H12 == 10
replace mccainideo6 = 4 if W6H12 == 12
replace mccainideo6 = 5 if W6H12 == 11
replace mccainideo6 = 6 if W6H11 == 11
replace mccainideo6 = 7 if W6H11 == 10

gen mccainideo9 = .
replace mccainideo9 = 1 if W9M10 == 10
replace mccainideo9 = 2 if W9M10 == 11
replace mccainideo9 = 3 if W9M12 == 10
replace mccainideo9 = 4 if W9M12 == 12
replace mccainideo9 = 5 if W9M12 == 11
replace mccainideo9 = 6 if W9M11 == 11
replace mccainideo9 = 7 if W9M11 == 10

gen obamaideo6 = .
replace obamaideo6 = 1 if W6H6 == 10
replace obamaideo6 = 2 if W6H6 == 11
replace obamaideo6 = 3 if W6H8 == 10
replace obamaideo6 = 4 if W6H8 == 12
replace obamaideo6 = 5 if W6H8 == 11
replace obamaideo6 = 6 if W6H7 == 11
replace obamaideo6 = 7 if W6H7 == 10

gen obamaideo9 = .
replace obamaideo9 = 1 if W9M6 == 10
replace obamaideo9 = 2 if W9M6 == 11
replace obamaideo9 = 3 if W9M8 == 10
replace obamaideo9 = 4 if W9M8 == 12
replace obamaideo9 = 5 if W9M8 == 11
replace obamaideo9 = 6 if W9M7 == 11
replace obamaideo9 = 7 if W9M7 == 10

**** perceived candidate differences 

* wave 6

gen gay6 = abs(gaymccain6-gayobama6)
gen tax6 = abs(taxmccain6-taxobama6)
gen script6 = abs(scriptmccain6-scriptobama6)
gen health6 = abs(healthmccain6-healthobama6)
gen terror6 = abs(terrormccain6-terrorobama6)
gen fisa6 = abs(fisamccain6-fisaobama6)
gen immigrants6 = abs(immigrantsmccain6-immigrantsobama6)
gen citizen6 = abs(citizenmccain6-citizenobama6)
gen ideo6 = abs(mccainideo6-obamaideo6)

factor gay6-ideo6, ipf
alpha gay6-ideo6, gen(canddiff6)

* wave 9

gen gay9 = abs(gaymccain9-gayobama9)
gen tax9 = abs(taxmccain9-taxobama9)
gen script9 = abs(scriptmccain9-scriptobama9)
gen health9 = abs(healthmccain9-healthobama9)
gen terror9 = abs(terrormccain9-terrorobama9)
gen fisa9 = abs(fisamccain9-fisaobama9)
gen immigrants9 = abs(immigrantsmccain9-immigrantsobama9)
gen citizen9 = abs(citizenmccain9-citizenobama9)
gen ideo9 = abs(mccainideo9-obamaideo9)

factor gay9-ideo9, ipf
alpha gay9-ideo9, gen(canddiff9)



******
*** affective
*** parties
******

* wave 6

gen dem6 = . 
replace dem6 = 4 if W6E2 == 12 
replace dem6 = 1 if W6E4 == 10
replace dem6 = 2 if W6E4 == 11
replace dem6 = 3 if W6E4 == 12
replace dem6 = 5 if W6E3 == 12
replace dem6 = 6 if W6E3 == 11
replace dem6 = 7 if W6E3 == 10


gen rep6 = . 
replace rep6 = 4 if W6E5 == 12 
replace rep6 = 1 if W6E7 == 10
replace rep6 = 2 if W6E7 == 11
replace rep6 = 3 if W6E7 == 12
replace rep6 = 5 if W6E6 == 12
replace rep6 = 6 if W6E6 == 11
replace rep6 = 7 if W6E6 == 10


* wave 9

gen dem9 = . 
replace dem9 = 4 if W9E2 == 12 
replace dem9 = 1 if W9E4 == 10
replace dem9 = 2 if W9E4 == 11
replace dem9 = 3 if W9E4 == 12
replace dem9 = 5 if W9E3 == 12
replace dem9 = 6 if W9E3 == 11
replace dem9 = 7 if W9E3 == 10


gen rep9 = . 
replace rep9 = 4 if W9E5 == 12 
replace rep9 = 1 if W9E7 == 10
replace rep9 = 2 if W9E7 == 11
replace rep9 = 3 if W9E7 == 12
replace rep9 = 5 if W9E6 == 12
replace rep9 = 6 if W9E6 == 11
replace rep9 = 7 if W9E6 == 10

** candidates 

gen mccain6 = .
replace mccain6 = 4 if W6E14 == 12
replace mccain6 = 1 if W6E16 == 10
replace mccain6 = 2 if W6E16 == 11
replace mccain6 = 3 if W6E16 == 12
replace mccain6 = 5 if W6E15 == 12
replace mccain6 = 6 if W6E15 == 11
replace mccain6 = 7 if W6E15 == 10

gen mccain9 = .
replace mccain9 = 4 if W9E14 == 12
replace mccain9 = 1 if W9E16 == 10
replace mccain9 = 2 if W9E16 == 11
replace mccain9 = 3 if W9E16 == 12
replace mccain9 = 5 if W9E15 == 12
replace mccain9 = 6 if W9E15 == 11
replace mccain9 = 7 if W9E15 == 10

gen obama6 = .
replace obama6 = 4 if W6E38 == 12
replace obama6 = 1 if W6E40 == 10
replace obama6 = 2 if W6E40 == 11
replace obama6 = 3 if W6E40 == 12
replace obama6 = 5 if W6E39 == 12
replace obama6 = 6 if W6E39 == 11
replace obama6 = 7 if W6E39 == 10

gen obama9 = .
replace obama9 = 4 if W9E38 == 12
replace obama9 = 1 if W9E40 == 10
replace obama9 = 2 if W9E40 == 11
replace obama9 = 3 if W9E40 == 12
replace obama9 = 5 if W9E39 == 12
replace obama9 = 6 if W9E39 == 11
replace obama9 = 7 if W9E39 == 10


******************************
*****
***** affective polarization
*****
******************************


gen party6 = abs(rep6-dem6)
gen party9 = abs(rep9-dem9)
gen cand6 = abs(mccain6-obama6)
gen cand9 = abs(mccain9-obama9)

alpha party6 cand6, gen(affect6)
alpha party9 cand9, gen(affect9)


********************************
********************************
********************************
********************************
*** Control variables 
********************************
********************************
********************************
********************************

*** ideology 

gen ideology1 = .
replace ideology1 = -3 if W1N2 == 10
replace ideology1 = -2 if W1N2 == 11
replace ideology1 = -1 if W1N4 == 10
replace ideology1 = 0 if W1N4 == 12
replace ideology1 = 1 if W1N4 == 11
replace ideology1 = 2 if W1N3 == 11
replace ideology1 = 3 if W1N3 == 10

gen ideostrength1 = abs(ideology1)



** wave 6
gen ideology6 = .
replace ideology6 = -3 if W6G2 == 10
replace ideology6 = -2 if W6G2 == 11
replace ideology6 = -1 if W6G4 == 10
replace ideology6 = 0 if W6G4 == 12
replace ideology6 = 1 if W6G4 == 11
replace ideology6 = 2 if W6G3 == 11
replace ideology6 = 3 if W6G3 == 10

gen ideostrength6 = abs(ideology6)

*** ONLY HAVE PID FROM WAVE 1 (and wave 9)
gen pid = .
replace pid = -3 if DER08W1 == 10
replace pid = -2 if DER08W1 == 11
replace pid = -1 if DER08W1 == 12
replace pid = 0 if DER08W1 == 13
replace pid = 1 if DER08W1 == 14
replace pid = 2 if DER08W1 == 15
replace pid = 3 if DER08W1 == 16

gen pidstrength = abs(pid)

gen black = 0
replace black = 1 if RRACEBLA == 11

gen age = .
replace age = RAGER if RAGER != 4
replace age = age+7

gen female = .
replace female = 0 if DER01 == 10
replace female = 1 if DER01 == 11

gen income = .
replace income = DER06 if DER06 > 9

gen education = .
replace education = DER05 if DER05 > 9


** political knowledfge

**** from WAVE 2 

gen k1 = 0
gen k2 = 0
gen k3 = 0
gen k4 = 0
gen k5 = 0
gen k6 = 0

replace k1 = 1 if W2U2 == 12
replace k1 = . if W2U2 < 10

replace k2 = 1 if W2U3 == 16
replace k2 = . if W2U3 < 10

replace k3 = 1 if W2U4 == 12
replace k3 = . if W2U4 < 10

replace k4 = 1 if W2U5 == 12
replace k4 = . if W2U5 < 10

replace k5 = 1 if W2U6 == 12
replace k5 = . if W2U6 < 10

replace k6 = 1 if W2U7 == 11
replace k6 = . if W2U7 < 10

alpha k1-k6, gen(knowledge)



** issue extremity

**** from WAVE 1 


* amend const for same sex
gen gaySelf = .
replace gaySelf = 0 if W1P1 == 12
replace gaySelf = 1 if W1P_O_2 == 10
replace gaySelf = 2 if W1P_O_2 == 11
replace gaySelf = 3 if W1P_O_2 == 12
replace gaySelf = 5 if W1P_F_2 == 12
replace gaySelf = 6 if W1P_F_2 == 11
replace gaySelf = 7 if W1P_F_2 == 10

* tax the rich
gen taxSelf = . 
replace taxSelf = 4 if W1P4 == 12
replace taxSelf = 1 if W1P_O_5 == 10
replace taxSelf = 2 if W1P_O_5 == 11
replace taxSelf = 3 if W1P_O_5 == 12
replace taxSelf = 5 if W1P_F_5 == 12
replace taxSelf = 6 if W1P_F_5 == 11
replace taxSelf = 7 if W1P_F_5 == 10

* gov pay for prescription drugs 
gen scriptSelf = .
replace scriptSelf = 4 if W1P10 == 12
replace scriptSelf = 1 if W1P_O_11 == 10
replace scriptSelf = 2 if W1P_O_11 == 11
replace scriptSelf= 3 if W1P_O_11 == 12
replace scriptSelf = 5 if W1P_F_11 == 12
replace scriptSelf = 6 if W1P_F_11 == 11
replace scriptSelf = 7 if W1P_F_11 == 10

* gov pay for medical care
gen healthSelf = .
replace healthSelf = 4 if W1P13 == 12
replace healthSelf = 1 if W1P_O_14 == 10
replace healthSelf = 2 if W1P_O_14 == 11
replace healthSelf= 3 if W1P_O_14 == 12
replace healthSelf = 5 if W1P_F_14 == 12
replace healthSelf = 6 if W1P_F_14 == 11
replace healthSelf = 7 if W1P_F_14 == 10

* detain terrorists 
gen terrorSelf = .
replace terrorSelf = 4 if W1P16 == 12
replace terrorSelf = 1 if W1P_O_17 == 10
replace terrorSelf = 2 if W1P_O_17 == 11
replace terrorSelf= 3 if W1P_O_17 == 12
replace terrorSelf = 5 if W1P_F_17 == 12
replace terrorSelf = 6 if W1P_F_17 == 11
replace terrorSelf = 7 if W1P_F_17 == 10

* Need FISA warrant to wiretap terrorists? 
gen fisaSelf = .
replace fisaSelf = 4 if W1P19 == 12
replace fisaSelf = 1 if W1P_O_20 == 10
replace fisaSelf = 2 if W1P_O_20 == 11
replace fisaSelf = 3 if W1P_O_20 == 12
replace fisaSelf = 5 if W1P_F_20 == 12
replace fisaSelf = 6 if W1P_F_20 == 11
replace fisaSelf = 7 if W1P_F_20 == 10

* Let immigrants work for 3 years, then send them back 
gen immigrantsSelf = .
replace immigrantsSelf = 4 if W1P22 == 12
replace immigrantsSelf = 1 if W1P_O_23 == 10
replace immigrantsSelf = 2 if W1P_O_23 == 11
replace immigrantsSelf = 3 if W1P_O_23 == 12
replace immigrantsSelf = 5 if W1P_F_23 == 12
replace immigrantsSelf = 6 if W1P_F_23 == 11
replace immigrantsSelf = 7 if W1P_F_23 == 10

* allowing immigrants to become citizens
gen citizenSelf = .
replace citizenSelf = 4 if W1P25 == 12
replace citizenSelf = 1 if W1P_O_26 == 10
replace citizenSelf = 2 if W1P_O_26 == 11
replace citizenSelf = 3 if W1P_O_26 == 12
replace citizenSelf = 5 if W1P_F_26 == 12
replace citizenSelf = 6 if W1P_F_26 == 11
replace citizenSelf = 7 if W1P_F_26 == 10

*recode
foreach var of varlist gaySelf-citizenSelf{ 
	recode `var' (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
	gen `var'2 = abs(`var')
}
*

alpha gaySelf2-citizenSelf2, gen(issueextremity)


**** south

gen south = 0
replace south = 1 if  W1XSTATE == 3
replace south = 1 if  W1XSTATE == 4
replace south = 1 if  W1XSTATE == 9
replace south = 1 if  W1XSTATE == 10
replace south = 1 if  W1XSTATE == 11
replace south = 1 if  W1XSTATE == 12
replace south = 1 if  W1XSTATE == 19
replace south = 1 if  W1XSTATE == 20
replace south = 1 if  W1XSTATE == 22
replace south = 1 if  W1XSTATE == 27
replace south = 1 if  W1XSTATE == 29
replace south = 1 if  W1XSTATE == 38
replace south = 1 if  W1XSTATE == 42
replace south = 1 if  W1XSTATE == 44
replace south = 1 if  W1XSTATE == 45
replace south = 1 if  W1XSTATE == 47
replace south = 1 if  W1XSTATE == 50

*** interest
gen i1 = W6Y2 if W6Y2 > 9
gen i2 = W6Y3 if W6Y3 > 9
gen i3 = W6Y4 if W6Y4 > 9
gen i4 = W6Y5 if W6Y5 > 9
gen i5 = W6Y8 if W6Y8 > 9
gen i6 = W6Y9 if W6Y9 > 9
gen i7 = W6Y10 if W6Y10 > 9

*recode
foreach var of varlist i1-i7{ 
	replace `var' = `var' - 9
	replace `var' = 6-`var'
}
*

alpha i1-i7, gen(interest6)


*rescale 0-1
foreach v of var canddiff6 canddiff9 ideostrength1 ideostrength6 ///
	age pidstrength income education issueextremity knowledge ////
	affect6 affect9 interest6 ideo9 ideo6 tax6{ 
	su `v', meanonly 
	gen `v'2 = (`v' - r(min))/(r(max) - r(min)) 
}
*

keep gaymccain6-interest62

********************************************************************************
	
****
** Panel models corresponding to 
** Table 1, columns 3-4
****	

sem (canddiff92 <- affect62 canddiff62 ideostrength62 pidstrength2 ///
	issueextremity2 interest62 knowledge2 education2 age2 income2 female ///
	black south) ///
	(affect92 <- affect62 canddiff62 ideostrength62 pidstrength2 ///
	issueextremity2 interest62 knowledge2 education2 age2 income2 female ///
	black south), standardized 
	
****
** Panel models stratified by sophistication
** corresponding to Table 2, bottom half
****		
	
gen knowalt = k1 + k2 + k3 + k4 + k5 + k6
sum knowalt, detail	
	
gen know4 = .
replace know4 = 1 if knowalt < 3
replace know4 = 2 if knowalt > 2 & knowalt < 5
replace know4 = 3 if knowalt > 4 & knowalt < .
	
sem (canddiff92 <- affect62 canddiff62 ideostrength62 pidstrength2 issueextremity2 ///
	interest62 education2 age2 income2 female ///
	black south) ///
	(affect92 <- affect62 canddiff62 ideostrength62 pidstrength2 issueextremity2 ///
	interest62 education2 age2 income2 female ///
	black south), standardized group(know4)		
	
